/*
 * 15 March 2008; Modified this class to have multiple tab layers - the reason for this is to allow for the view to 
                  contain multiple tab views within tab views. Have tried just adding it as a widget but strange 
                  behavour starts happening so it's probably easier managed explicitly via this class. 
 */

package net.ubinow.mflex.widgets;


import java.util.Enumeration;
import java.util.Vector;

import javax.microedition.lcdui.Canvas;
import javax.microedition.lcdui.Graphics;
import javax.microedition.lcdui.Image;

import net.ubinow.mflex.baseui.AbsController;
import net.ubinow.mflex.baseui.ITransistion;
import net.ubinow.mflex.baseui.IWidget;
import net.ubinow.mflex.baseui.SimpleTransition;
import net.ubinow.mflex.baseui.WFont;
import net.ubinow.mflex.events.Event;
import net.ubinow.mflex.util.Constants;
import net.ubinow.mflex.util.MiscUtil;

/**
 *
 * @author Josh
 */
public class TabView extends AbsView {

    //<editor-fold defaultstate="collapsed" desc="tab variables">
    private int _bgTabColour = 0x000000;
    private Image _selTabImage = null;
    private Image _tabImage = null;
    private Image _tabFocusImage = null;
    private Image _leftArrowImage = null; 
    private Image _rightArrowImage = null;
    
    // positions are always releative to the x/y position and their associated offsets, thus the view can 
    // dynamically move around without having to recalculate these values
    private int _lArrowPosX = 0;
    private int _lArrowPosY = 0;
    private int _rArrowPosX = 0;
    private int _rArrowPosY = 0;
    
    // x offset forced on the tabs when they're not visible ie if the tab is not actually on the screen then this 
    // offset will be set to move them all along so it becomes visible on the screen
    private int _tabOffsetX = 0;
    private int _tabOffsetFinalX = 0;
    
    private int _tabImageHeight = -1; // derived from the tab image 
    private int _tabImageWidth = -1; // derived from the tab image 
    
    private int _tabContentVPadding = 10; // padding between (vertically) the tab and the tabs widgets
    private int _tabContentHPadding = 0; // horizontal padding between the _x position and widgets
    
    private int _tabSpacing = 0; // spacing between each of the tabs
    
    private int _selectedTabIndex = -1; 
    private Tab _selectedTab = null;    
    private Tab _previousTab = null;
    private boolean _tabsSelected = true; // flag to indicate that the tab selection component of this view is selected  
    
    private Vector _tabs = null; // TODO: change this to an array when finished to improve performance ... 
    //</editor-fold>
    
    //<editor-fold defaultstate="collapsed" desc="header variables">
    
    private Image _headerImg = null;
    private Image _headerIcon = null; 
    private int _headerIconX = 0;
    private int _headerIconY = 0;
    private String _headerText = null;
    private int _headerTextX = 0;
    private int _headerTextY = 0;
    
    //</editor-fold>
    
    //<editor-fold defaultstate="collapsed" desc="other variables">
    
    private MiscUtil _miscUtil = null;
    
    private ITransistion _transOut = null;
    private ITransistion _transIn = null;
    
    //</editor-fold>
    
    //<editor-fold defaultstate="collpased" desc="constrcutors and initilisation methods">
    
    public TabView( int x, int y, int width, int height, WFont defaultFont, Image tabImage, Image tabFocusImage, Image selTabImage, 
            Image leftArrowImage, Image rightArrowImage, int bgTabColour, Image headerBGImage, 
            Image headerIcon, int alignIcon, String headerText, int alignText ){
        
        this( x, y, width, height, defaultFont, tabImage, tabFocusImage, selTabImage, leftArrowImage, rightArrowImage, 
                bgTabColour );                
        
        if( headerBGImage != null ){
            setHeaderImage( headerBGImage );            
        }
        
        if( headerIcon != null ){
            setHeaderIcon( headerIcon, Constants.AD_POS_HEADER_ICON_X, Constants.AD_POS_HEADER_ICON_Y, 
                    alignIcon ); 
        }
        
        if( headerText != null ){
            setHeaderText( headerText, Constants.AD_POS_HEADER_TEXT_X, Constants.AD_POS_HEADER_TEXT_Y, alignText );
        } 
        
        init2();               
    }   
    
    public TabView( int x, int y, int width, int height, WFont defaultFont, Image tabImage, Image tabFocusImage, Image selTabImage, 
            Image leftArrowImage, Image rightArrowImage, int bgTabColour ){
        super( x, y, width, height, defaultFont );
        
        _tabImage = tabImage;
        _tabFocusImage = tabFocusImage;
        _selTabImage = selTabImage;
        _leftArrowImage = leftArrowImage;
        _rightArrowImage = rightArrowImage;
        _bgTabColour = bgTabColour;                                
        
        init();
        init2();  
        
        _miscUtil = MiscUtil.getInstance();
    }        
    
    private void init(){
        _tabImageHeight = _tabImage.getHeight();
        _tabImageWidth = _tabImage.getWidth();
        
        // set the width and height to the larget of the tabs 
        if( _tabFocusImage != null ){
            if( _tabImageHeight < _tabFocusImage.getHeight() )
                _tabImageHeight = _tabFocusImage.getHeight();
            
            if( _tabImageWidth < _tabFocusImage.getWidth() )
                _tabImageWidth = _tabFocusImage.getWidth();
        }
        
        if( _selTabImage != null ){
            if( _tabImageHeight < _selTabImage.getHeight() )
                _tabImageHeight = _selTabImage.getHeight();
            
            if( _tabImageWidth < _selTabImage.getWidth() )
                _tabImageWidth = _selTabImage.getWidth();
        }
        
        _tabs = new Vector();
        
        // create new transitions 
        _transIn = new SimpleTransition( AbsController.gScreenWidth, AbsController.gScreenHeight );
        _transOut = new SimpleTransition( AbsController.gScreenWidth, AbsController.gScreenHeight );
                        
    }
    
    private void init2(){
        _viewableHeight = _height - (_tabImageHeight-_tabContentVPadding);
        
        if( _headerImg != null )
            _viewableHeight -= _headerImg.getHeight();
        
        _lArrowPosX = 0;
        _lArrowPosY = _tabImageHeight - _leftArrowImage.getHeight(); 
        if( _headerImg != null )
            _lArrowPosY += _headerImg.getHeight();
        
        _rArrowPosX = _width-_rightArrowImage.getWidth(); 
        _rArrowPosY = _tabImageHeight - _leftArrowImage.getHeight(); 
        if( _headerImg != null )
            _rArrowPosY += _headerImg.getHeight();                 
        
    }
    
    //</editor-fold>
    
    //<editor-fold defaultstate="collapsed" desc="overrides">
    
    private boolean _isChild = false;
    /**
     * call this method on initilisation when the tab view is a sub container for another view
     */
    public void setAsChild(){
        _isChild = true;
        setFocus( false, Constants.DIRECTION_UNDEFINED );
    }
    
    public void setFocus( boolean focus ,int direction ){
        super.setFocus( focus, direction ); 
        
        if( direction == Constants.DIRECTION_UP ){
            _tabsSelected = false;
            
            if( _selectedTab != null ){
                // get the last widget 
                _selectedTab.getWidgetContainer().selectLastWidget(); // make the last widget selected
                _selectedTab.setFocus( true, Constants.DIRECTION_UP );
            }
        }
        else{
            _tabsSelected = focus;
        }          
    }
    
    public boolean isSelectable(){
        return true; 
    }
    
    //</editor-fold>

    //<editor-fold defaultstate="collapsed" desc="processing methods">
    
    public void cycle() {
        
        // ease the tab scrolling 
        if( _tabOffsetX != _tabOffsetFinalX )
             _tabOffsetX += MiscUtil.getInstance().calcHalfDistance( _tabOffsetFinalX, _tabOffsetX );
        
        if( _previousTab != null )
            _previousTab.cycle();
        
        if( _selectedTab != null )
            _selectedTab.cycle();
    }

    public void paint(Graphics g, int offsetX, int offsetY, int layer) {
        
        _miscUtil.clip( g, _x + offsetX, _y + offsetY, _width, _height );
        
        if( _bgColour != -1 ){
            g.setColor( _bgColour );
            g.drawRect( _x + offsetX, _y + offsetY, _width, _height );
        }
        
        if( _bgImage != null ){
            g.drawImage( _bgImage, _x + offsetX, _y + offsetY, Constants.GFX_ALIGN_TOP_LEFT );
        }  
        
        // draw widgets
        if( _selectedTab != null ){
            _selectedTab.paint( g, offsetX, offsetY, 1 );
//            System.out.println("painting: " + _selectedTab.getId() + ", osx: " + offsetX);
        }
        
        // draw tabs
        if( _tabs != null ){
            int posX = _x+_tabOffsetX;
            int finalPosX = _x+_tabOffsetFinalX;
            
            int tabTop = getTabTop();
            
            Enumeration enumTabs = _tabs.elements();
            while( enumTabs.hasMoreElements() ){
                Tab tab = (Tab)enumTabs.nextElement();
                
                if( tab == _selectedTab ){    
                    // if out of the screen to modify the offset so that is it fully on the screen 
                    // left and right bounds checking 
                    if( finalPosX+offsetX < _x )
                        _tabOffsetFinalX += _x-(posX+offsetX);
                    else if( finalPosX+offsetX+_tabImageWidth > _x + _width )
                        _tabOffsetFinalX += (_x+_width)-(finalPosX+offsetX+_tabImageWidth);
                    
                    if( !_tabsSelected && _tabFocusImage != null )
                        g.drawImage(_tabFocusImage, posX+offsetX, tabTop+offsetY, Graphics.LEFT | Graphics.TOP );
                    else
                        g.drawImage(_selTabImage, posX+offsetX, tabTop+offsetY, Graphics.LEFT | Graphics.TOP );
                }
                else{
                    g.drawImage(_tabImage, posX+offsetX, tabTop+offsetY, Graphics.LEFT | Graphics.TOP );
                }
                
                // draw title and/or icon 
                if( tab.hasTabIcon() ){
                    if( tab == _selectedTab ){                       
                        g.drawImage( tab.getSelTabIcon(), posX+tab.getTabIconX()+offsetX, tabTop+tab.getTabIconY()+offsetY, Graphics.LEFT | Graphics.TOP );
                    }
                    else{
                        g.drawImage( tab.getTabIcon(), posX+tab.getTabIconX()+offsetX, tabTop+tab.getTabIconY()+offsetY, Graphics.LEFT | Graphics.TOP );
                    }
                }
                
                if( tab.hasTabTitle() ){
                    _bodyFont.drawString( g, tab.getTabTitle(), posX+tab.getTabTitleX()+offsetX, tabTop+tab.getTabTitleY()+offsetY );
                }
                
                posX += _tabImageWidth;
                finalPosX += _tabImageWidth;
            }
        }
        
        // draw arrows
        if( _tabsSelected ){
            if( _rightArrowImage != null ){
                g.drawImage( _rightArrowImage, _rArrowPosX+_x+offsetX, _rArrowPosY+_y+offsetY, Graphics.LEFT | Graphics.TOP );
            }
            
            if( _leftArrowImage != null )
                g.drawImage( _leftArrowImage, _lArrowPosX+_x+offsetX, _lArrowPosY+_y+offsetY, Graphics.LEFT | Graphics.TOP );
        }
        
        // draw header
        if( _headerImg != null ){
            g.drawImage( _headerImg, 0, 0, Constants.GFX_ALIGN_TOP_LEFT );
        }
        
        if( _headerIcon != null ){
            g.drawImage( _headerIcon, _headerIconX, _headerIconY, Constants.GFX_ALIGN_TOP_LEFT );
        }
        
        if( _headerText != null ){
            _headerFont.drawString( g, _headerText, _headerTextX, _headerTextY );
        }
        
        // draw command bar
        if( _cmdBar != null ){
            _cmdBar.paint( g, offsetX, offsetY, 0 );
        }
        
        
        _miscUtil.releaseClip( g );         
    }

    public boolean handleKeyPressed(int action, int keyCode) {
        
        // process tab navigation (left and right)
        if( _tabsSelected ){
            if( action == Canvas.LEFT ){
                moveToLeftTab();
                return true; 
            }
            else if( action == Canvas.RIGHT ){
                moveToRightTab();
                return true;
            }
            else if( action == Canvas.DOWN ){                
                if( _selectedTab != null && _selectedTab.getWidgetContainer().getWidgetCount() > 0 ){
                    _selectedTab.setFocus( true, Constants.DIRECTION_DOWN );                    
                    _tabsSelected = false;
                }                
                return true; 
            }
            else if( action == Canvas.UP ){

                _tabsSelected = false;
                if( _isChild )
                    return false; 
                
                if( _selectedTab != null ){
                    // get the last widget 
                    _selectedTab.getWidgetContainer().selectLastWidget(); // make the last widget selected
                    _selectedTab.setFocus( true, Constants.DIRECTION_UP );
                }                
                return true;
            }
        }
        else if( _selectedTab != null ){
            boolean handled = _selectedTab.handleKeyPressed( action, keyCode );
            if( !handled && (action == Canvas.UP || action == Canvas.LEFT) ){
                _tabsSelected = true; 
                handled = true; 
            }
            return handled; 
        }
        
        return false;         
    }

    public boolean handleKeyReleased(int action, int keyCode) {
        if( _selectedTab != null ){
            return _selectedTab.handleKeyReleased( action, keyCode );
        }
        else{
            return false; 
        }
    }
    
    public void handleEvent(Event evt) {        

        if( evt._type == Event.EVT_OFF_FOCUS && evt._value != null ){
            int direction = Integer.parseInt( String.valueOf( evt._value ) );
            
            if( _selectedTab != null )
                _selectedTab.getWidgetContainer().setFocus( false, direction );
            
            _tabsSelected = true; 
            
            evt.release();
        }
        else{
            super.handleEvent( evt );
        }        
    }
    
    //</editor-fold>
    
    //<editor-fold defaultstate="collapsed" desc="header methods">
    
    public void setHeaderImage( Image img ){
        _headerImg = img; 
    }
    
    public void setHeaderIcon( Image ico, int xPadding, int y, int align ){
        _headerIcon = ico;
        
        // work out x
        if( (align & Constants.ALIGN_LEFT) != 0 ){
            _headerIconX = xPadding; 
        }
        else if( (align & Constants.ALIGN_RIGHT) != 0 ){
            _headerIconX = _width - (_headerIcon.getWidth()-xPadding ); 
        }
        else if( (align & Constants.ALIGN_LEFT) != 0 ){
            _headerIconX = (_width-(_headerIcon.getWidth()+xPadding))>>1; 
        }
        else{
            _headerIconX = 0;
        }
        
        _headerIconY = y; 
        
    }
    
    public void setHeaderText( String title, int xPadding, int y, int align ){
        _headerText = title; 
        
        // work out x and y         
        if( (align & Constants.ALIGN_LEFT) == Constants.ALIGN_LEFT ){
            _headerTextX = xPadding; 
        }
        else if( (align & Constants.ALIGN_RIGHT) == Constants.ALIGN_RIGHT ){
            if( _headerFont != null ){
                _headerTextX = _width - (_headerFont.stringWidth(_headerText)-xPadding ); 
            }
        }
        else if( (align & Constants.ALIGN_CENTRE_H) == Constants.ALIGN_CENTRE_H ){
            if( _headerFont != null ){
                _headerTextX = (_width - (_headerFont.stringWidth(_headerText) ))>>1; 
            }
        }
        else{
            _headerTextX = 0;
        }        
        
        _headerTextY = y; 
    }
    
    //</editor-fold>
    
    //<editor-fold defaultstate="collapsed" desc="Tab handling methods">
    
    //<editor-fold defaultstate="collapsed" desc="Tab handling methods - adding">        
    
    private boolean _useInitValues = false; 
    
    private int _tmpTabPaddingX = 0;
    private int _tmpTabPaddingY = 0;
    private int _tmpContainerPaddingX = 0;
    private int _tmpContainerPaddingY = 0;    
    
    public void initTabPadding( int tabPaddingX, int tabPaddingY, int containerPaddingX, int containerPaddingY ){
        _tmpTabPaddingX = tabPaddingX;
        _tmpTabPaddingY = tabPaddingY;
        _tmpContainerPaddingX = containerPaddingX;
        _tmpContainerPaddingY = containerPaddingY;
        _useInitValues = true; 
    }
    
    public void addTab( String id, String name, Image tabIcon, Image selTabIcon, IWidget[] widgets ){
        this.addTab( id, name, tabIcon, selTabIcon, widgets, true, true );
    }
    
    public void addTab( String id, String name, Image tabIcon, Image selTabIcon, IWidget[] widgets, boolean padHorizontally, boolean padVertically ){
        
        int paddingX = 0;
        int paddingY = 0;
                
        if( padHorizontally ){
            if( _useInitValues )
                paddingX = _tmpTabPaddingX;
            else
                paddingX = _tabContentHPadding;
        }
        if( padVertically ){
            if( _useInitValues )
                paddingY = _tmpTabPaddingY;
            else
                paddingY = _tabContentVPadding;
        }
        
        Tab tab = new Tab( id, this, tabIcon, selTabIcon, name, 
                _x+paddingX, getTabTop()+_tabImageHeight+paddingY, _width-_tabContentHPadding, getTabHeight() );
        
        if( _useInitValues ){
            tab.getWidgetContainer().setPaddingW( _tmpContainerPaddingX );
            tab.getWidgetContainer().setPaddingH( _tmpContainerPaddingY );
        }
        
        if( widgets != null && widgets.length > 0 ){
            int len = widgets.length;
            for( int i=0; i<len; i++ ){
                tab.getWidgetContainer().addWidget( widgets[i], false );
            }
        }
        
        // set the tabs text position 
        if( tab.hasTabTitle() ){
            int titleLen = _bodyFont.stringWidth( tab.getTabTitle() );
            int titleHeight = _bodyFont.getHeight();
            
            tab.setTabTitleX( (_tabImageWidth-titleLen)>>1 );
            tab.setTabTitleY( (_tabImageHeight-titleHeight)>>1 );
        }
        
        if( tab.hasTabIcon() ){
            tab.setTabIconX( (_tabImageWidth - tab.getTabIcon().getWidth() )>>1 );
            tab.setTabIconY( (_tabImageHeight - tab.getTabIcon().getHeight() )>>1 );
        }
        
        // register some events we might be interested in.
        // register interest in EVT_OFF_FOCUS so we know when the user 
        // has gone 'off-focus' on the widget container so that the tabs can gain control again
        tab.getWidgetContainer().addEventSubscriber( Event.EVT_OFF_FOCUS, this );
                
        _tabs.addElement( tab );                
        
        if( _selectedTabIndex == -1 ){
            _selectedTabIndex = 0;
            _selectedTab = tab;
            _tabsSelected = true; 
        }
        
        _useInitValues = false; 
    }
    
    public void addTab( String id, String name ){
        this.addTab( id, name, null, null, null );
    }
    
    public void addTab( String id, String name, boolean padHorizontally, boolean padVertically ){
        this.addTab( id, name, null, null, null, padHorizontally, padVertically );
    }
    
    public void addTab( String id, Image tabIcon, Image selTabIcon ){
        this.addTab( id, null, tabIcon, selTabIcon, null );
    }
    
    public void addTab( String id, Image tabIcon, Image selTabIcon, boolean padHorizontally, boolean padVertically ){
        this.addTab( id, null, tabIcon, selTabIcon, null, padHorizontally, padVertically );
    }
    
    //</editor-fold>
    
    //<editor-fold defaultstate="collapsed" desc="Tab handling methods - inserting">
    
    public void insertTab( String id, String name, Image tabIcon, Image selTabIcon, IWidget[] widgets, int position ){
        System.out.println("Not supported yet - TabView.insertTab");
    }
    
    public void insertTab( String id, String name, int position ){
        System.out.println("Not supported yet - TabView.insertTab");
    }
    
    public void insertTab( String id, Image tabIcon, Image selTabIcon, int position ){
        System.out.println("Not supported yet - TabView.insertTab");
    }
    
    //</editor-fold>
    
    //<editor-fold defaultstate="collapsed" desc="Tab handling methods - removing">
    
    public void removeTab( String id ){
        System.out.println("Not supported yet - TabView.removeTab");
    }
    
    public void removeTab( int id ){
        System.out.println("Not supported yet - TabView.removeTab");
    }
    
    //</editor-fold>
    
    //<editor-fold defaultstate="collapsed" desc="Tab handling methods - tab widget management">        
    
    public void addWidget( int index, IWidget widget ){
        Tab tab = getTab( index );
         if( tab == null )
             return;
        
        tab.getWidgetContainer().addWidget( widget, false );
    }
    
    public void addWidget( String tabId, IWidget widget ){
        Tab tab = getTab( tabId );
        
        if( tab == null || widget == null )
            return;
        
        tab.getWidgetContainer().addWidget( widget, false );
    }
    
    /** 
     * add a widget to the selected tab
     * @param widget
     */
    public void addWidget( IWidget widget ){
        
        if( widget instanceof TabView ){
            System.out.println("tab view");
        }
        
        if( _selectedTab != null ){
            _selectedTab.getWidgetContainer().addWidget( widget, false );
        }
    }
    
    //</editor-fold>
    
    //<editor-fold defaultstate="collapsed" desc="Tab handling methods - misc">
    
    public Tab getTab( int index ){
        if( _tabs != null && index >= 0 && index < _tabs.size() ){
            return (Tab)_tabs.elementAt(index);
        }
        else{
            return null;
        }
    }
    
    public Tab getTab( String id ){
        if( _tabs == null || _tabs.size() == 0 )
            return null;
        
        Enumeration enumTabs = _tabs.elements();
        while( enumTabs.hasMoreElements() ){
            Tab tab = (Tab)enumTabs.nextElement();
            
            if( tab.getId().equals( id ) ) 
                return tab;
        }
        
        return null;        
    }
    
    public int getTabIndex( String id ){
        if( _tabs == null || _tabs.size() == 0 )
            return -1;
        
        int index = -1;
        
        Enumeration enumTabs = _tabs.elements();
        while( enumTabs.hasMoreElements() ){
            index++;
            Tab tab = (Tab)enumTabs.nextElement();
            
            if( tab.getId().equals( id ) ) 
                return index;
        }
        
        return -1;        
    }
    
    /**
     * set the current tab to view
     * @param index
     */
    public void moveToLeftTab(){
        _tabsSelected = true; 
        
        if( _tabs.size() <= 1 )
            return; 
                
        _selectedTabIndex--;
        
        if( _selectedTabIndex < 0 )
            _selectedTabIndex = _tabs.size()-1; 
        
        if( _transOut != null )
            _transOut.setTransitionOutType( ITransistion.TRANSITION_FLY_LEFT );
        
        if( _transIn != null )
            _transIn.setTransitionInType( ITransistion.TRANSITION_FLY_LEFT );
        
        if( _selectedTab != null ){
            _previousTab = _selectedTab;        
            if( _previousTab.supportsTransitioning() )
                _previousTab.getWidgetContainer().setTransition( _transOut );            
            _previousTab.getWidgetContainer().hide();
        }
        
        _selectedTab = (Tab)_tabs.elementAt( _selectedTabIndex );
        if( _selectedTab.supportsTransitioning() )
            _selectedTab.getWidgetContainer().setTransition( _transIn );
        _selectedTab.getWidgetContainer().show();
        
    }       
    
    /**
     * set the current tab to view
     * @param tabId
     */
    public void moveToRightTab(){
        _tabsSelected = true; 
        
        if( _tabs.size() <= 1 )
            return; 
                
        _selectedTabIndex++;
        
        if( _selectedTabIndex >= _tabs.size() )
            _selectedTabIndex = 0; 
        
        if( _transOut != null )
            _transOut.setTransitionOutType( ITransistion.TRANSITION_FLY_RIGHT );
        
        if( _transIn != null )
            _transIn.setTransitionInType( ITransistion.TRANSITION_FLY_RIGHT );
        
        if( _selectedTab != null ){
            _previousTab = _selectedTab;
            if( _previousTab.supportsTransitioning() )
                _previousTab.getWidgetContainer().setTransition( _transOut );
            _previousTab.getWidgetContainer().hide();
        }
        
        _selectedTab = (Tab)_tabs.elementAt( _selectedTabIndex );
        if( _selectedTab.supportsTransitioning() )
            _selectedTab.getWidgetContainer().setTransition( _transIn );
        _selectedTab.getWidgetContainer().show();
        
    }
    
    //</editor-fold>
    
    //</editor-fold>
    
    //<editor-fold defaultstate="collapsed" desc="private helper methods">
    
    /**
     * returns the top position of where the actual contents of a tab should start
     * @return
     */
    private int getTabTop(){
        int tt = _y;
        
        if( _headerImg != null )
            tt += _headerImg.getHeight();
        
        return tt;
    }
    
    /**
     * returns the height of the tabs relative to the views and tabs size
     * @return
     */
    private int getTabHeight(){
        int tabContentHeight = _height-(_tabImageHeight+_tabContentVPadding);
        
        if( _headerImg != null )
            tabContentHeight -= _headerImg.getHeight();
        
        return tabContentHeight;
    }
    
    //</editor-fold>

}
